<?php
$config_arr = array();

$config_arr['host'] = trim($_POST['server_name']);
$config_arr['username']  = trim($_POST['user_name']);
$config_arr['password']  = trim($_POST['password']);
$config_arr['dbname'] = trim($_POST['database']);
$config_arr['charset']  = trim($_POST['data_encode']);

$prefix  = trim($_POST['prefix']);

if(!empty($prefix)){

	$config_arr['prefix'] = $prefix;
}

$config_arr['driver'] = 'mysql';
$config_arr['port'] = '3306';

define('CONFIG_ROOT', substr(dirname(__FILE__), 0, -10).'config/');

if(!is_dir(CONFIG_ROOT)) {
				
	mkdir(CONFIG_ROOT, 0777);
}

$config_file_name = CONFIG_ROOT.'config.ini.php';

if(file_exists($config_file_name)){

	echo 'Config配置文件已存在!';

	exit;
}
else{

	$file_content = "<?php\n// +---------------------------------------------------------------\n// |	Tommy FrameWork\n// +---------------------------------------------------------------\n// | Copyright (c) 2009 http://tommycode.com All rights reserved.\n// +---------------------------------------------------------------\n// | Author: streen003 <streen003gmail.com>\n// +---------------------------------------------------------------\n\nreturn ".var_export($config_arr,true).";\n?>";
    
	$result = file_put_contents($config_file_name, $file_content, LOCK_EX);

	if(!$result){

		echo 'Config配置文件创建失败!';
	}
	else{

		echo 'Config配置文件创建成功!';
	}
}
?>